package org.puremvc.as3.multicore.demos.flex.hellopipes.shell
{
	import org.puremvc.as3.multicore.demos.flex.hellopipes.shell.controller.AddMessageCommand;
	import org.puremvc.as3.multicore.demos.flex.hellopipes.shell.controller.ModuleRemovedCommand;
	import org.puremvc.as3.multicore.demos.flex.hellopipes.shell.controller.StartupCommand;
	import org.puremvc.as3.multicore.interfaces.IFacade;
	import org.puremvc.as3.multicore.patterns.facade.Facade;	

	/**
	 * Concrete Facade for the Main App / Shell.
	 */
	public class ApplicationFacade extends Facade implements IFacade
	{
		//
		// vars
		
		//
		// const	
		public static const STARTUP:String = 'startup';
		
		public static const MODULE_ADDED: String = "moduleAdded";
		public static const MODULE_REMOVED: String = "moduleRemoved";

		public static const SEND_MESSAGE_TO_MODULE: String = "sendMessageToModule";				
		public static const MESSAGE_FROM_MODULE_RECEIVED: String = "messageFromModuleReceived";
		//
		// instances
				
		/**
		* Constructor of ApplicationFacade
		*
		*/				
		public function ApplicationFacade( key:String )
		{
			super(key);	
		}

        /**
         * Singleton ApplicationFacade Factory Method
         */
        public static function getInstance( key:String ) : ApplicationFacade
        {
            if ( instanceMap[ key ] == null ) instanceMap[ key ]  = new ApplicationFacade( key );
            return instanceMap[ key ] as ApplicationFacade;
        }
        
	    /**
         * Register Commands with the Controller 
         */
        override protected function initializeController( ) : void 
        {
            super.initializeController(); 
                     
            registerCommand( STARTUP, StartupCommand );
            registerCommand( MESSAGE_FROM_MODULE_RECEIVED, AddMessageCommand );
            registerCommand( MODULE_REMOVED, ModuleRemovedCommand );
        }
        
        /**
         * Application startup
         * 
         * @param app a reference to the application component 
         */  
        public function startup( app: HelloPipesShell ):void
        {
        	sendNotification( STARTUP, app );
        }
			
	}
}